package com.fcgzs.sms.listener;

import com.fcgzs.sms.utils.SmsUtils;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

/**
 * @Auther: ljj
 * @Description:
 */
@Component
public class SmsListener {

    @Autowired
    private SmsUtils smsUtils;

    @RabbitListener(queues = "yigoushangcheng.sms.queue")
    public void sendMessage(Map<String,String> map){
        //1.接收消息队列的消息
        String mobile = map.get("mobile");
        String code = map.get("code");
        //2.调用发送短信的方法
        HttpResponse response = smsUtils.sendSms(mobile, code);
        try {
            System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
